package com.matt.repository.statistics;

import com.matt.domain.statistics.StatNurseryCount;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/8/6
 * *******************************
 */
public interface StatNurseryCountRepository extends JpaRepository<StatNurseryCount, String>{
    StatNurseryCount findByAreaIdAndCreatedBetween(String areaId, Date begin, Date end);

    @Query(value = "select count(c.id) from children c, children_extend_info i where c.id =i.childrenId and i.nurseryStatus =:nurseryStatus and c.aid = :areaId", nativeQuery = true)
    Long countNurseryCountByArea(@Param("nurseryStatus") Integer nurseryStatus, @Param("areaId") String areaId);

    @Query(value = "select sum(limitNum) as count from classes WHERE areaId = :areaId and category=:category", nativeQuery = true)
    Long countNurseryLimitByArea(@Param("areaId") String areaId, @Param("category") Integer category);
}
